import { useEffect, useRef, useState } from 'react'

function App() {
  const [count, setCount] = useState(0)
  let timeId = useRef()
  useEffect(() => {
    timeId.current = setInterval(() => {
      setCount(count => count + 1)
    }, 1000)
  }, [])
  const box = useRef()
  const handler = () => console.log(box)
  return (
    <div ref={box}>
      <span>{count}</span>
      <button onClick={handler}>获取div</button>
      <button onClick={() => clearInterval(timeId.current)}>停止</button>
    </div>
  )
}

export default App
